﻿
using StoreSQLSugar.Models.ViewModel;
using StoreSQLSugar_.DBUtility;
using StoreSQLSugar_.Helpers;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StoreSQLSugar_
{
    public partial class LoginFrm : Form
    {
        public LoginFrm()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            //1 效验
            if (string.IsNullOrWhiteSpace(txtAccount.Text))
            {
                MessageBox.Show("请输入账号!","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
                return;
            }
            if (string.IsNullOrWhiteSpace(txtPassword.Text))
            {
                MessageBox.Show("请输入密码!","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
                return;
            }
            //2 查询数据库
            var user = SqlSugarHelper.Db.Queryable<VUser>().Where(u => u.Account == txtAccount.Text&&u.Password==txtPassword.Text).Single();
            if (user == null) 
            {
                MessageBox.Show("账号或密码错误!","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
                return;
            }
            //保存登录信息
            LoginHelper.User=user;
           DialogResult = DialogResult.OK;
        }
    }
}
